////////////////////////////////////////
// 				Information			  //
////////////////////////////////////////

// Investor Memory (Katrin Gödker, Peiran Jiao, Paul Smeets)
// Replication code for results from Experiment 1

////////////////////////////////////////
// 				Settings			  //
////////////////////////////////////////

// Stata settings:
version 15

// Import file: Use Data_Experiment1.dta

////////////////////////////////////////
// 				Dataset 			  //
////////////////////////////////////////

// Unique subject IDs are generated for clarity, pseudonymized lab IDs are deleted.

// Treatment variable
// Groups: 1=no memory elicitation, 2=memory elicitation with delay, 3=immediate memory elicitation
destring treatment, replace
gen Treatment = 0
replace Treatment = 1 if treatment == 2
replace Treatment = . if treatment == 1

// Memory bias
// "high" is positive outcomes, "low" is negative outcomes
// "final" is true number of outcomes observed
gen MemoryBiasPos = MemoryNumberHigh - NumberHighFinal
gen MemoryBiasNeg = MemoryNumberLow - NumberLowFinal

gen MemoryBiasPosAbs = abs(MemoryBiasPos)
gen MemoryBiasNegAbs = abs(MemoryBiasNeg)
gen MemoryBias = MemoryBiasPosAbs + MemoryBiasNegAbs

// Type of observed stock
// SeeGoodStock means that the subject observed outcomes which in the end imply a good-type stock based on Bayesian posterior
// Left means the stock was shown left in the table during the experimental choice
gen SeeGoodStock = 0
replace SeeGoodStock = 1 if GoodStockLeft == 1 & ChoiceLeft == 1
replace SeeGoodStock = 1 if GoodStockLeft == 0 & ChoiceLeft == 0

gen SeeBadStock = 0
replace SeeBadStock = 1 if GoodStockLeft == 1 & ChoiceLeft == 0
replace SeeBadStock = 1 if GoodStockLeft == 0 & ChoiceLeft == 1

// Objective Bayesian Posterior that the stock is of the good type
gen Prob100 = ProbFinal*100
gen Prob100Int = int(Prob100)

// Subjective posterior that the stock is of the good type: BeliefGoodStock

// Belief distortion (i.e., difference between the posterior log-likelihood ratios of subjects’ elicited probabilities and the objective Bayesian probabilities)
gen BeliefDistortion = (ln(BeliefGoodStock / (100-BeliefGoodStock))) - (ln(Prob100 / (100-Prob100)))

// Investment: Choice1Stock == 1 if subject invested in the stock in task 1

// Reinvestment
// Choice2Stock == 1 if subject invested in stock in Task 2
// Invest2_low == 1 if subject invested in stock in Task 2 although Bayesian posterior that the stock is the good-type stock is lower than 53.1%

gen Invest2_low = 0
replace Invest2_low = 1 if Choice2Stock == 1 & Prob100 <53.1

// Variable names for tables
label variable MemoryBiasPos "Memory Bias (Pos. Out.)"
label variable MemoryBiasNeg "Memory Bias (Neg. Out.)"
label variable Prob100 "Objective Prob."
label variable Treatment "Treatment (Delay)"

////////////////////////////////////////
// 				Analyses 			  //
////////////////////////////////////////

// FIGURE 1
cibar MemoryBiasPos, over1(Treatment) level(95) graphopts(title("Positive Outcomes") legend(off) xlabel(1 "Immediate" 2 "Delay") ytitle("Recalled minus true outcomes") ) baropts(fcolor(gs14) lcolor(black) lwidth(0.3))
cibar MemoryBiasNeg, over1(Treatment) level(95) graphopts(title("Negative Outcomes") legend(off) xlabel(1 "Immediate" 2 "Delay") ytitle("Recalled minus true outcomes") ) baropts(fcolor(gs14) lcolor(black) lwidth(0.3))

// FIGURE 2

// Split memory bias in delay and immediate treatment
// mean memory bias in delay treatment:  2.467391
// mean memory bias in immediate treatment:  1.4375
gen MemoryBiasDummyDel = 0
replace MemoryBiasDummyDel = 1 if MemoryBias >= 2.467391
gen MemoryBiasDummyImm = 0
replace MemoryBiasDummyImm = 1 if MemoryBias >= 1.4375

// Both panels: restricted to the sample of stock holders
// Panel A: Immediate condition
regress BeliefGoodStock i.Prob100Int i.MemoryBiasDummyImm if Choice1Stock == 1 & Treatment == 0, robust
margins Prob100Int if Choice1Stock == 1 & Treatment == 0, over(MemoryBiasDummyImm)
marginsplot, level(95)

// Panel B: Delay condition
regress BeliefGoodStock i.Prob100Int i.MemoryBiasDummyDel if Choice1Stock == 1 & Treatment == 1, robust
margins Prob100Int if Choice1Stock == 1 & Treatment == 1, over(MemoryBiasDummyDel)
marginsplot, level(95)

// FIGURE 3
cibar Invest2_low if Choice1Stock == 1, over1 (Treatment) level(95) graphopts(title("") legend(off) xlabel(1 "Immediate" 2 "Delay") ytitle("Fraction of subjects") ) baropts(fcolor(gs14) lcolor(black) lwidth(0.3))

// TABLE 2

ttest MemoryBiasPos == 0 if Treatment == 0 & Choice1Stock == 1
ttest MemoryBiasNeg == 0 if Treatment == 0 & Choice1Stock == 1

ttest MemoryBiasPos == 0 if Treatment == 1 & Choice1Stock == 1
ttest MemoryBiasNeg == 0 if Treatment == 1 & Choice1Stock == 1

ttest MemoryBiasPos if Choice1Stock == 1, by (Treatment)
ttest MemoryBiasNeg if Choice1Stock == 1, by (Treatment)

// TABLE 3
eststo clear
eststo: xi: reg BeliefGoodStock MemoryBiasPos Prob100 i.session
eststo: xi: reg BeliefGoodStock MemoryBiasNeg Prob100 i.session
eststo: xi: reg BeliefDistortion MemoryBiasPos i.session
eststo: xi: reg BeliefDistortion MemoryBiasNeg i.session
esttab using reg_beliefs.tex,  ///
star(* 0.10 ** 0.05 *** 0.01)  b(3) se(2) label mtitles("Subj. Prob." "Subj. Prob." "Belief Dist." "Belief Dist.")  ///
replace stats(N r2,  fmt(%12.0fc %12.2fc) labels("N" "$ R^2 $")) order(MemoryBiasPos MemoryBiasNeg Prob100) indicate("Session=*sess*") drop() nogaps tex prehead(`"{"' \begin{scriptsize} `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' \begin{tabular}{l*{@E}{l}} \toprule) posthead("\midrule") prefoot("\midrule") postfoot(`"\bottomrule"'  \end{tabular} \end{scriptsize} }) 

// TABLE 4
eststo clear
eststo: xi: logit Choice2Stock Treatment i.session if Choice1Stock == 1, or 
eststo: xi: logit Invest2_low Treatment i.session if Choice1Stock == 1, or 
eststo: xi: logit Invest2_low MemoryBiasPos i.session if Choice1Stock == 1, or 
eststo: xi: logit Invest2_low MemoryBiasNeg i.session if Choice1Stock == 1, or
esttab using reg_reinvestment.tex, eform ///
star(* 0.10 ** 0.05 *** 0.01) se(2) label mtitles("Inv." "Inv. (Subopt.)" "Inv. (Subopt.)" "Inv. (Subopt.)")  ///
replace stats(N r2_p, fmt(%12.0fc %12.2fc) labels("N" "Pseudo $ R^2 $")) order(Treatment MemoryBiasPos MemoryBiasNeg) indicate("Session=*sess*") constant drop() nogaps tex prehead(`"{"' \begin{scriptsize} `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' \begin{tabular}{l*{@E}{l}} \toprule) posthead("\midrule") prefoot("\midrule") postfoot(`"\bottomrule"'  \end{tabular} \end{scriptsize} }) 
